/**
 * 聊天模块store
 * */
let mnemonicInfo = []
let registerInfo = {}
let token = ''
let userInfo = {}
try {
	token = uni.getStorageSync('POOL_TOKEN')
	userInfo = uni.getStorageSync('POOL_USER_INFO') || {}
 	mnemonicInfo = uni.getStorageSync('POOL_MNEMONIC') || []
	registerInfo = uni.getStorageSync('POOL_REGISTER') || {}
 } catch (e) {}
export default {
	state: {
		token: token,
		userInfo: userInfo
	},
	actions: {
		//写入
		setToken: ({ commit }, token) => {
			commit('setToken', token)
			try {
				uni.setStorageSync('POOL_TOKEN', token);
			} catch (e) {}
		},
		setUserInfo: ({ commit }, info) => {
			commit('setUserInfo', info)
			try {
				uni.setStorageSync('POOL_USER_INFO', info);
			} catch (e) {}
		},
		setMnemonic: ({ commit }, data) => {
			try {
				uni.setStorageSync('POOL_MNEMONIC', data) 
			} catch (e) {}
			commit('setMnemonic', data);
		},
		setRegister: ({ commit }, data) => {
			try {
				uni.setStorageSync('POOL_REGISTER', data) 
			} catch (e) {}
			commit('setRegister', data);
		},
		logout: ({ commit }, data) => {
			try {
				uni.setStorageSync('POOL_TOKEN', '');
				uni.setStorageSync('POOL_USER_INFO', {});
			} catch (e) {
			}
			commit('logout', data);
		}
	},
	getters: {
		mnemonic: state => state.mnemonic,
		register: state => state.register,
		getToken: state => state.token,
		userInfo: state => state.userInfo
	},
	mutations: {
		setToken: (state, token) => {
			state.token = token
		},
		setUserInfo: (state, info) => {
			state.userInfo = info
		},
		setMnemonic: (state, info) => {
			state.mnemonic = info
		},
		setRegister: (state, info) => {
			state.register = info
		},
		logout: (state, data) => {
			state.token = '',
			state.userInfo = {}
		}
	},
	namespaced: true
};
